#! /bin/sh
#
# Copyright 2017 DT42
# 
# This file is part of BerryNet.
# 
# BerryNet is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# BerryNet is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with BerryNet.  If not, see <http://www.gnu.org/licenses/>.

help() {
    echo "Usage: $0 <start | stop | status | log>"
    echo "       start  : launch dlsystem"
    echo "       stop   : terminate dlsystem"
    echo "       status : check the state of all services"
    echo "       log    : dump logfiles of all services"
    exit 1
}

if [ $# -lt 1 ]
    then
        help
fi

case $1 in
  start | stop | status)
	sudo systemctl $1 detection_server.service agent.service broker.service dashboard.service localimg.service camera.service journal.service cleaner.timer
    ;;
  log)
	sudo journalctl -x --no-pager -u detection_server.service
	sudo journalctl -x --no-pager -u agent.service
	sudo journalctl -x --no-pager -u broker.service
	sudo journalctl -x --no-pager -u dashboard.service
	sudo journalctl -x --no-pager -u localimg.service
	sudo journalctl -x --no-pager -u camera.service
	sudo journalctl -x --no-pager -u journal.service
	sudo journalctl -x --no-pager -u cleaner.timer
    ;;
  *)
    help
esac 
